package com.blog.common.newclass.dostringabs;

import com.blog.util.StrUtils;
import com.blog.common.newclass.inteface.DoStr;

/**
 * 加密：隐藏中间的字符串
 */
public class DoEntryMind extends DoEntryAbs {

    public static final int MIND_NUM = 3;
    public static final String REPLASE_STR = "***";

    public DoEntryMind(DoStr doStr){
        super(doStr);
    }

    @Override
    public String getStr() throws Exception {
        String source = super.getStr();
        int firstIndex = (source.length() / 2) - (MIND_NUM / 2);
        if (source.length() <= MIND_NUM)
            return REPLASE_STR;
        String[] strs = StrUtils.getFirstAndLastArr(source, firstIndex, firstIndex+MIND_NUM);
        return strs[0]  + REPLASE_STR + strs[1];
    }

    @Override
    public int cost() {
        return super.cost()+1;
    }

}